import java.util.Arrays;

/**
 * @program: 1.15 栈和队列
 * @description:
 * @author: 李鑫月
 * @create: 2022-01-15 11:11
 **/
public class MyStack {
    public int[] elem;
    public int usedSize;
    public MyStack(){
        this.elem=new int [5];
    }
    public  void push(int val){
        if(isFull()){
            this.elem=Arrays.copyOf(this.elem,this.elem.length*2);
        }
        this.elem[this.usedSize]=val;
        this.usedSize++;
    }
    public boolean isFull(){
        return this.usedSize==this.elem.length;
    }
    public int  pop(){
        if(isEmpty()){
            throw new RuntimeException("栈为空");

        }
        usedSize--;
        return this.elem[usedSize];
    }
    public int  peek(){
        if(isEmpty()){
            throw new RuntimeException("栈为空");
        }

        return this.elem[usedSize];
    }
    public boolean isEmpty(){
        return this.usedSize==0;
    }
}
